<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <input id="ipt" placeholder="请输入姓名" />
  <script type="text/javascript">
    // 	延迟执行，最后一次触发后生效
    // 关注结果（如搜索）
    // 电梯等人（关门最后一人）
    function debounce(fn) {
      console.log("调用")
      let timeout = null;
      return function() {
        clearTimeout(timeout);
        timeout = setTimeout(()=>{
          fn.apply(this,arguments)
        },1000)
      }
    }
    function sayHi() {
      console.log('防抖成功')
    }
    document.getElementById('ipt').addEventListener('input',debounce(sayHi))
  </script>
</body>
</html>